package cn.mccraft.uide.api.element;

import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;

import cn.mccraft.uide.api.property.PropertyHolder;
import cn.mccraft.uide.api.property.PropertyHolderBase;
import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;

import cn.mccraft.uide.api.property.key.Key;
import cn.mccraft.uide.api.property.value.Value;

//TODO:
public abstract class ElementBase extends PropertyHolderBase implements Element {

	@Override
	public void deserialize(JsonObject object) {
		for (Entry<Key<?>, Value<?>> entry : properties.entrySet()) {
			JsonElement element = object.get(entry.getKey().getName());
			if (element == null)
				continue;

			entry.getValue().deserialize(element);
		}
	}

	@Override
	public void serialize(JsonObject object) {
		for (Entry<Key<?>, Value<?>> entry : properties.entrySet()) {
			object.add(entry.getKey().getName(), entry.getValue().serialize());
		}
	}
}
